﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;
using BMS.Syncro.Devices.Message;
using BMS.Syncro.Devices.Persister;
using BMS.Syncro.Devices.Handler.Interfaces;
using BMS.Syncro.Devices.Configuration.Interfaces;
using BMS.Syncro.Devices.Message.Interfaces;
using BMS.Syncro.Devices.Persister.Interfaces;
using BMS.Syncro.Devices.Configuration.Entities;

namespace BMS.Syncro.Devices.Handler
{
    public class DefaultSychroHandler<T> : IHandler<T>
    {
        private readonly ILog _log = null;
        public IConfiguration Configuration { get; set; }
        //public IGenericPersister<SyncroMessage> PersisterMessage { get; set; }

        public DefaultSychroHandler()
        {
            _log = LogManager.GetLogger(this.GetType());
        }

        #region IHandler<T> Members

        public string ProcessName
        {
            get
            {
                return this.GetType().Name;
            }
        }

        public void Handler(T message)
        {
            Configuration.LoadConfigurations();
            // Proceso especial para la sincronización de dispositivos
            _log.Info("Iniciando proceso de sincronización.");

        }

        /// <summary>
        /// Get a synchro message for update the biometric device
        /// </summary>
        /// <param name="message"></param>
        /// <param name="configuration"></param>
        /// <returns></returns>
        private SyncroMessage GetSyncroMessage(T message, DeviceConfigurationEntity configuration )
        {
            return new SyncroMessage()
            {
                Action = Message.Entities.DeviceAction.Save,
                Device = new DeviceMessage()
                {
                    IpAddress = configuration.Ip,
                    Name = configuration.Name
                },
                Visitor = new VisitorMessage()
                {
                    DocumentNumber = ""
                }
            };
        }

        #endregion

    }
}
